﻿/*****************************************************************************
 * Hyldahl.Services.TaskProcessing.Test            Created by: MSH 2008.07.22
 * --------------------------------------------------------------------------
 * FileName: FibonacciCalculationTaskProcessorTest.cs
 * --------------------------------------------------------------------------
 * Copyright 2009 Martin Sixhøj Hyldahl
 *****************************************************************************/

using System;
using Hyldahl.Services.TaskProcessing.FibonacciCalculation;
using NUnit.Framework;

namespace Hyldahl.Services.TaskProcessing.Test
{
    
    
    /// <summary>
    ///This is a test class for FibonacciCalculationTaskProcessorTest and is intended
    ///to contain all FibonacciCalculationTaskProcessorTest Unit Tests
    ///</summary>
    [TestFixture()]
    public class FibonacciCalculationTaskProcessorTest
    {
        /// <summary>
        ///A test for TaskType
        ///</summary>
        [Test()]
        public void TaskTypeTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();
            string actual = target.TaskType;

            Assert.AreEqual("Fibonacci", actual);
        }

        /// <summary>
        ///A test for Process
        ///</summary>
        [Test()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ProcessNullTaskTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();

            target.Process(null);
        }

        /// <summary>
        ///A test for Process
        ///</summary>
        [Test()]
        [ExpectedException(typeof(ArgumentException))]
        public void ProcessInvalidTaskTypeTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();

            Task task = new Task();
            task.TaskType = "Unknown task type";

            target.Process(task);
        }

        /// <summary>
        ///A test for Process
        ///</summary>
        [Test()]
        [ExpectedException(typeof(ArgumentException))]
        public void ProcessInvalidTaskDataTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();

            Task task = new Task();
            task.TaskType   = "Fibonacci";
            task.Data       = "asdf";

            target.Process(task);
        }

                /// <summary>
        ///A test for Process
        ///</summary>
        [Test()]
        [ExpectedException(typeof(ArgumentException))]
        public void ProcessInvalidTaskDataNumberTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();

            Task task = new Task();
            task.TaskType   = "Fibonacci";
            task.Data       = "-10";

            target.Process(task);
        }

        /// <summary>
        ///A test for Process
        ///</summary>
        [Test()]
        [ExpectedException(typeof(ArgumentException))]
        public void ProcessNullTaskDataTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();

            Task task = new Task();
            task.TaskType   = "Fibonacci";
            task.Data       = null;

            target.Process(task);
        }

        /// <summary>
        ///A test for Process
        ///</summary>
        [Test()]
        public void ProcessTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();

            int[] expected = new int[] { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765 };

            for (int x = 0; x <= 20; x++)
            {
                Task task = new Task();
                task.TaskType   = "Fibonacci";
                task.Data       = x.ToString();

                target.Process(task);

                Assert.IsTrue(task.IsProcessed);
                Assert.IsTrue(task.CompletedSuccessfully.Value);
                
                Assert.AreEqual(expected[x], int.Parse(task.ResultData));
            }

        }

        /// <summary>
        ///A test for CalculateFibonacci
        ///</summary>
        [Test()]
        public void CalculateFibonacciTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();

            int[] expected = new int[] {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765};

            for (int x = 0; x <= 20; x++)
            {
                int actual = target.CalculateFibonacci(x);
                Assert.AreEqual(expected[x], actual);
            }
        }

        /// <summary>
        ///A test for FibonacciCalculationTaskProcessor Constructor
        ///</summary>
        [Test()]
        public void FibonacciCalculationTaskProcessorConstructorTest()
        {
            FibonacciCalculationTaskProcessor target = new FibonacciCalculationTaskProcessor();
        }
    }
}
